class Solution {
    public int search(int[] nums, int target) {
        int p=0;
        int q=nums.length-1;
        while(p<=q)
        {
            int h=(p+q)/2;
            if(target==nums[h]){
                return h;
            }
            else if(target<nums[h])
            {
                q=h-1;
            }
            else if(target>nums[h])
            {
                p=h+1;
            }
        }
        return -1;
    }
}
